package com.hitgo.soccer.database;

import java.sql.SQLException;
import java.util.ArrayList;

import com.danga.MemCached.MemCachedClient;
import com.hitgo.soccer.core.Player;

public class PlayerDAO extends BaseDAO
{
	public static Player[] getPlayers(Long lTeamID)
	{
		MemCachedClient mc = CacheFactory.getMCClient();
		String cacheKey = "getPlayers_" + lTeamID;
		ArrayList<Player> ap = (ArrayList<Player>) mc.get(cacheKey);
		if(ap == null)
		{
			try
			{
				ap = (ArrayList<Player>) BaseDAO.queryForList(lTeamID, "getPlayers", lTeamID);
				if(ap != null)
					mc.set(cacheKey, ap);
				
			}
			catch (SQLException e)
			{
				e.printStackTrace();
				return null;
			}
		}
		int nSize = ap.size();
		Player[] pa = new Player[nSize];
		for(int nIndex = 0; nIndex < nSize; nIndex++)
		{
			pa[nIndex] = ap.get(nIndex);
		}
			
		return pa;
	}
	
	public static Player getPlayer(Player player)
	{
		Player pData = null;
		try
		{
			pData = (Player) BaseDAO.queryForList(player.getUserID(), "getPlayer", player);
		}
		catch (SQLException e)
		{
			e.printStackTrace();
			return null;
		}
			
		return pData;
	}
	// 
	public static void updatePlayer(Player player)
	{
		
	}
	
	public static void insertPlayer(Player p)
	{
		
	}
}
